package com.example.su_shi_tan_bas_lib.view.fragment_tabhost;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.example.su_shi_tan_bas_lib.R;


public class JssTabIndicatorView extends LinearLayout {

    private TextView tvTabHint;

    private JssTabInfo homeTab;

    private ImageView icon_tab;


    public JssTabIndicatorView(Context context) {
        this(context, null);
    }

    public JssTabIndicatorView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public JssTabIndicatorView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        // 将布局文件和 代码进行绑定
        View.inflate(context, R.layout.jss_tab_indicator_view, this);
        tvTabHint = findViewById(R.id.tvTabHint);
        icon_tab=findViewById(R.id.icon_tab);
    }


    // 设置tab的title
    public void setTabTitle(String title) {
        if (tvTabHint != null) {
            tvTabHint.setText(title);
        }
    }

    public String getTabTitle() {
        if (tvTabHint != null) {
            return tvTabHint.getText().toString().trim() + "";
        }
        return "";
    }

    public void setTabTitle(int titleId) {
        if (tvTabHint != null) {
            tvTabHint.setText(titleId);
        }
    }

    public TextView getTvTabHint() {
        return tvTabHint;
    }

    public ImageView getIcontab() {
        return icon_tab;
    }

    public JssTabInfo getHomeTab() {
        return homeTab;
    }

    public void setHomeTab(JssTabInfo homeTab) {
        this.homeTab = homeTab;
        setTabTitle(homeTab.getTitle());
        setTabIcon(homeTab.getNormalIconId());
    }


    public void setTabIcon(int IconId) {
        if (icon_tab != null) {
            icon_tab.setImageResource(IconId);
        }
    }

    public void setSelect(boolean isSelect) {
        if (tvTabHint != null) {
            tvTabHint.setSelected(isSelect);
            icon_tab.setSelected(isSelect);
        }
    }

}
